// scaup - Scala up!
// (c) 2008-2010, Normen Müller, normen.mueller@gmail.com
// Original version by Jeremy Cloud (http://github.com/jjmmcc/scala0.cmdline#)
// $Id: CmdlnTst.scala 48 2010-01-13 08:02:13Z normen.mueller $
package scaup.draft.cmdln

object MyApplication {
  
  object Options extends CommandLineParser {
    val version  = Flag("v", "version", "Print version number and quit")
    val help     = Flag("?", "help", "Print help and quit")
    val dir      = StringOption("d", "dir", "dir", "output directory")
    val filename = NakedArgument("filename", "The name of the file")
    
    val versionMode  = %(version)
    val helpMode     = %(help)
    val filenameMode = %(dir?, filename)
    val spec = %%(versionMode, helpMode, filenameMode)
    
    //val dirMode = %(dir?)
    //val filenameMode = %(filename)    
    //val spec = %%(versionMode, helpMode, dirMode, filenameMode)
    
    //val nop = NoOptions
    //val nopMode = %(nop)
    //val spec = %%(nopMode)
  }

  def main(args: Array[String]) {
    
    var myargs = Array("-?")
    
    Options(myargs) match {
      case Left(error) =>
        Console.err.println(error)
        Options.printHelp("MyApplication")
        
      case Right((Options.versionMode, _)) =>
        Console.out.println("Version 1.0")
        
      case Right((Options.helpMode, _)) =>
        Options.printHelp("MyApplication")
                
      case Right((Options.filenameMode, cmdLine)) =>
        val dir = cmdLine(Options.dir).getOrElse("./")
        val filename = cmdLine(Options.filename).head
        
        println(dir+filename) // do something...
    }
  }
  
}
